package com.stateflow.facade.common.util;


import com.stateflow.facade.common.model.ToString;
import com.stateflow.facade.common.model.req.CommonRequest;
import com.stateflow.facade.common.template.CommonTemplate;

/**
 * Created by weiqingming on 2020/1/10.
 */
public class CreateRequestUtils {


    /**
     * 创建内部调用使用的CommonRequest
     * @param param
     * @return
     */
    public static CommonRequest createByInside(Object param){
        CommonRequest result = new CommonRequest();
        result.setParam(param);
        result.setReqType("INSIDE");

        // 设置traceId
        if (param instanceof ToString){
            ToString p = (ToString) param;
            if (StringUtils.isNotBlank(p.getTraceId())){
                result.setTraceId(p.getTraceId());
            }
        }

        // 没有旧值，设置新的traceId
        if (!StringUtils.isNotBlank(result.getTraceId())) {
            result.setTraceId(CommonTemplate.getTraceId());
        }
        return result;
    }

}
